#include <iostream>
using namespace std;
class Solution {
public:
    string compressString(string S) {
        if(S.size() == 0)
            return S;
        else
        {
            char ch = S[0];
            int count = 1;
            string str = "";
            for (int i = 1; i < S.size(); ++i)
            {
                if(S[i] == ch)
                    ++count;
                else
                {
                    str += ch + to_string(count);
                    count = 1;
                    ch = S[i];
                }
            }
            str += ch + to_string(count);
            return str.size() >= S.size() ? S : str;
        }
    }
};

int main()
{
    Solution sol;
    cout << sol.compressString("aaaabbccc") << endl;
    return 0;
}